home *** CD-ROM | disk | FTP | other *** search
/ Aminet 7 / Aminet 7 - August 1995.iso / Aminet / docs / misc / ConcNews.lha / news / amiga.programming / comp.sys.amiga.programmer_3886_000020.msg < prev    next >
Encoding:
Internet Message Format  |  1994-11-27  |  4.6 KB

  1. Path: dd.chalmers.se!news.chalmers.se!sunic!pipex!howland.reston.ans.net!darwin.sura.net!hearst.acc.Virginia.EDU!adastra!mbs
  2. Newsgroups: comp.sys.amiga.programmer
  3. From: mbs@adastra.cvl.va.us (Michael B. Smith)
  4. Subject: Re: Using Display Database
  5. Distribution: world
  6. References:  <CJEw08.466@dm.unibo.it>
  7. X-NewsSoftware: GRn 2.0j Jan 8, 1994
  8. MIME-Version: 1.0
  9. Content-Type: text/plain; charset=iso-8859-1
  10. Content-Transfer-Encoding: 8bit
  11. Message-ID: <mbs.2n2o@adastra.cvl.va.us>
  12. Date: Mon, 10 Jan 94 22:14:00 EDT
  13. Organization: Well, I haven't decided on a name yet...
  14. Lines: 170
  15.  
  16. In article <CJEw08.466@dm.unibo.it> favre@cs.unibo.it (Dimitri Favre) writes:
  17. > I'm developping a tool and I need to allow user to use whatever screen
  18. > it wants. I'm searching a demo code showing how to use the display database
  19. > (I mean, the Monitors in Devs:Monitors) to implement a WorkBench like
  20. > screen Requester (even through GadToolBox).
  21.  
  22. Here is some example code from GRn. It compiles with commercial and
  23. registered DICE; but should be trivial to modify for SAS/C. It DOES
  24. require asl.library v38 or higher. Regardless, you can take the
  25. information from ModeSize() and FitWB() and come up with routines
  26. that should work on v37 as well.
  27. --
  28.   //   Michael B. Smith
  29. \X/    mbs@adastra.cvl.va.us  -or-  uunet.uu.net!virginia.edu!adastra!mbs
  30.  
  31. static ULONG
  32. ModeSize (ULONG modeID, int *x, int *y)
  33. {
  34.     /*
  35.     **  ModeSize
  36.     **
  37.     **    Returns the size of the passed ModeID.
  38.     **    The 'X' and 'Y' sizes are stored in the parameters.
  39.     **
  40.     **    On failure, returns INVALID_ID.
  41.     **    On success, returns modeID.
  42.     */
  43.     struct DimensionInfo
  44.         di;
  45.  
  46.     if (GetDisplayInfoData (NULL, (void *) &di, sizeof di, DTAG_DIMS, modeID)) {
  47.         *x = di.TxtOScan.MaxX - di.TxtOScan.MinX + 1;
  48.         *y = di.TxtOScan.MaxY - di.TxtOScan.MinY + 1;
  49.         return modeID;
  50.     }
  51.  
  52.     return INVALID_ID;
  53. }
  54.  
  55. static ULONG
  56. FitWB (int *x, int *y)
  57. {
  58.     /*
  59.     **  FitWB:   returns the modeID which "first fits" the passed X and
  60.     **         Y parameters, and is suitable for a Workbench screen.
  61.     **
  62.     **  On failure, returns INVALID_ID.
  63.     */
  64.  
  65.     ULONG
  66.         modeID = INVALID_ID;
  67.     int
  68.         X = 0,
  69.         Y = 0;
  70.     struct DisplayInfo
  71.         ds;
  72.  
  73.     while ((modeID = NextDisplayInfo (modeID)) != INVALID_ID) {
  74.  
  75.         if (ModeNotAvailable (modeID))
  76.             continue;
  77.  
  78.         if ((modeID & MONITOR_ID_MASK) == DEFAULT_MONITOR_ID)
  79.             continue;
  80.  
  81.         if (GetDisplayInfoData (NULL, (void *) &ds, sizeof (struct DisplayInfo), DTAG_DISP, modeID))
  82.             if (!(ds.PropertyFlags & DIPF_IS_WB))
  83.                 continue;
  84.  
  85.         if (ModeSize (modeID, &X, &Y) != INVALID_ID) {
  86.             if (X >= *x && Y >= *y) {
  87.                 *x = X;
  88.                 *y = Y;
  89.                 return modeID;
  90.             }
  91.         }
  92.     }
  93.  
  94.     return INVALID_ID;
  95. }
  96.  
  97. #define MINIMUM_HEIGHT        200
  98. #define MINIMUM_WIDTH        600
  99.  
  100. __geta4 __asm ULONG
  101. ScreenModeHook (__a0 struct Hook *myhook,
  102.         __a2 struct ScreenModeRequester *myScreenReq,
  103.         __a1 APTR data)
  104. {
  105.     ULONG
  106.         modeID = (ULONG) data;
  107.     int
  108.         x,
  109.         y;
  110.  
  111.     if (ModeNotAvailable (modeID))
  112.         return FALSE;
  113.  
  114.     if (ModeSize (modeID, &x, &y) == INVALID_ID)
  115.         return FALSE;
  116.  
  117.     if (x < MINIMUM_WIDTH || y < MINIMUM_HEIGHT)
  118.         return FALSE;
  119.  
  120.     return TRUE;
  121. }
  122.  
  123. int
  124. GetScreenMode (ULONG *modeID, int *height, int *width, int *autoscroll)
  125. {
  126.     int
  127.         rslt,
  128.         mode_width  = *width ? *width : DEFAULT_WIDTH,
  129.         mode_height = *height ? *height : DEFAULT_HEIGHT;
  130.     ULONG
  131.         pref_mode = FitWB (&mode_width, &mode_height);
  132.     struct Hook
  133.         ScreenReqHook;
  134.     struct ScreenModeRequester
  135.         *screenReq;
  136.     static const char
  137.         routine [] = { "GRn - Select Screen Mode" };
  138.  
  139.     ScreenReqHook.h_Data = NULL;
  140.     ScreenReqHook.h_Entry = (ULONG (*)()) ScreenModeHook;
  141.     ScreenReqHook.h_SubEntry = NULL;
  142.  
  143.     screenReq = (struct ScreenModeRequester *) AllocAslRequestTags (ASL_ScreenModeRequest,
  144.         /*
  145.         ** initial conditions
  146.         */
  147.         ASLSM_InitialDisplayID,     pref_mode,
  148.         ASLSM_InitialDisplayWidth,  mode_width,
  149.         ASLSM_InitialDisplayHeight, mode_height,
  150.         /*
  151.         ** setup stuff
  152.         */
  153.         ASLSM_SleepWindow,  TRUE,
  154.         ASLSM_TitleText,    routine,
  155.         ASLSM_MinWidth,     MINIMUM_WIDTH,
  156.         ASLSM_MinHeight,    MINIMUM_HEIGHT,
  157.         ASLSM_FilterFunc,   &ScreenReqHook,
  158.         /*
  159.         ** what can the user specify
  160.         */
  161.         ASLSM_DoWidth,        TRUE,
  162.         ASLSM_DoHeight,     TRUE,
  163.         ASLSM_DoAutoScroll, TRUE,
  164.         TAG_DONE);
  165.  
  166.     if (!screenReq) {
  167.         panic ("Failed, couldn't allocate ScreenModeRequester");
  168.     }
  169.  
  170.     if (!AslRequest (screenReq, NULL)) {
  171.         rslt = 0;
  172.     }
  173.     else {
  174.         *modeID = screenReq->sm_DisplayID;
  175.         *height = screenReq->sm_DisplayHeight;
  176.         *width    = screenReq->sm_DisplayWidth;
  177.         *autoscroll = screenReq->sm_AutoScroll;
  178.         rslt = 1;
  179.     }
  180.  
  181.     FreeAslRequest (screenReq);
  182.  
  183.     return rslt;
  184. }
  185.